home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / flex-2.4.6 / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-23  |  24.3 KB  |  997 lines  |  [TEXT/KAHL]

  1. /* flex - tool to generate fast lexical analyzers */
  2.  
  3. /*-
  4.  * Copyright (c) 1990 The Regents of the University of California.
  5.  * All rights reserved.
  6.  *
  7.  * This code is derived from software contributed to Berkeley by
  8.  * Vern Paxson.
  9.  * 
  10.  * The United States Government has rights in this work pursuant
  11.  * to contract no. DE-AC03-76SF00098 between the United States
  12.  * Department of Energy and the University of California.
  13.  *
  14.  * Redistribution and use in source and binary forms are permitted provided
  15.  * that: (1) source distributions retain this entire copyright notice and
  16.  * comment, and (2) distributions including binaries display the following
  17.  * acknowledgement:  ``This product includes software developed by the
  18.  * University of California, Berkeley and its contributors'' in the
  19.  * documentation or other materials provided with the distribution and in
  20.  * all advertising materials mentioning features or use of this software.
  21.  * Neither the name of the University nor the names of its contributors may
  22.  * be used to endorse or promote products derived from this software without
  23.  * specific prior written permission.
  24.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  25.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  26.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27.  */
  28.  
  29. #ifndef lint
  30. char copyright[] =
  31. "@(#) Copyright (c) 1990 The Regents of the University of California.\n\
  32.  All rights reserved.\n";
  33. #endif /* not lint */
  34.  
  35. /* $Header: main.c,v 1.2 94/01/04 14:33:11 vern Exp $ */
  36.  
  37.  
  38. #include "flexdef.h"
  39. #include "version.h"
  40. #ifdef THINK_C
  41. #include <console.h>
  42. #endif
  43.  
  44. static char flex_version[] = FLEX_VERSION;
  45.  
  46.  
  47. /* declare functions that have forward references */
  48.  
  49. void flexinit PROTO((int, char**));
  50. void readin PROTO((void));
  51. void set_up_initial_allocations PROTO((void));
  52.  
  53.  
  54. /* these globals are all defined and commented in flexdef.h */
  55. int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt;
  56. int interactive, caseins, lex_compat, useecs, fulltbl, usemecs;
  57. int fullspd, gen_line_dirs, performance_report, backing_up_report;
  58. int C_plus_plus, long_align, use_read, yytext_is_array, csize;
  59. int yymore_used, reject, real_reject, continued_action;
  60. int yymore_really_used, reject_really_used;
  61. int datapos, dataline, linenum;
  62. FILE *skelfile = NULL;
  63. int skel_ind = 0;
  64. char *action_array;
  65. int action_size, defs1_offset, prolog_offset, action_offset, action_index;
  66. char *infilename = NULL;
  67. int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
  68. int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
  69. int current_mns, num_rules, num_eof_rules, default_rule;
  70. int current_max_rules, lastnfa;
  71. int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2;
  72. int *accptnum, *assoc_rule, *state_type;
  73. int *rule_type, *rule_linenum, *rule_useful;
  74. int current_state_type;
  75. int variable_trailing_context_rules;
  76. int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
  77. int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
  78. int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs, tecfwd[CSIZE + 1];
  79. int tecbck[CSIZE + 1];
  80. int lastsc, current_max_scs, *scset, *scbol, *scxclu, *sceof, *actvsc;
  81. char **scname;
  82. int current_max_dfa_size, current_max_xpairs;
  83. int current_max_template_xpairs, current_max_dfas;
  84. int lastdfa, *nxt, *chk, *tnxt;
  85. int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz;
  86. union dfaacc_union *dfaacc;
  87. int *accsiz, *dhash, numas;
  88. int numsnpairs, jambase, jamstate;
  89. int lastccl, current_maxccls, *cclmap, *ccllen, *cclng, cclreuse;
  90. int current_max_ccl_tbl_size;
  91. Char *ccltbl;
  92. char nmstr[MAXLINE];
  93. int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
  94. int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
  95. int num_backing_up, bol_needed;
  96. FILE *backing_up_file;
  97. int end_of_buffer_state;
  98. char **input_files;
  99. int num_input_files;
  100. char *program_name;
  101.  
  102. #ifndef SHORT_FILE_NAMES
  103. static char *outfile_template = "lex.%s.%s";
  104. #else
  105. static char *outfile_template = "lex%s.%s";
  106. #endif
  107. static char outfile_path[64];
  108.  
  109. static int outfile_created = 0;
  110. static int use_stdout;
  111. static char *skelname = NULL;
  112. static char *prefix = "yy";
  113.  
  114.  
  115. int main( argc, argv )
  116. int argc;
  117. char **argv;
  118.     {
  119.     int i;
  120.  
  121. #ifdef THINK_C
  122.     argc = ccommand(&argv);
  123. #endif
  124.  
  125.     flexinit( argc, argv );
  126.  
  127.     readin();
  128.  
  129.     ntod();
  130.  
  131.     for ( i = 1; i <= num_rules; ++i )
  132.         if ( ! rule_useful[i] && i != default_rule )
  133.             line_warning( "rule cannot be matched",
  134.                     rule_linenum[i] );
  135.  
  136.     if ( spprdflt && ! reject && rule_useful[default_rule] )
  137.         line_warning( "-s option given but default rule can be matched",
  138.             rule_linenum[default_rule] );
  139.  
  140.     /* Generate the C state transition tables from the DFA. */
  141.     make_tables();
  142.  
  143.     /* Note, flexend does not return.  It exits with its argument
  144.      * as status.
  145.      */
  146.     flexend( 0 );
  147.  
  148.     return 0;    /* keep compilers/lint happy */
  149.     }
  150.  
  151.  
  152. /* flexend - terminate flex
  153.  *
  154.  * note
  155.  *    This routine does not return.
  156.  */
  157.  
  158. void flexend( exit_status )
  159. int exit_status;
  160.  
  161.     {
  162.     int tblsiz;
  163.     int unlink();
  164.  
  165.     if ( skelfile != NULL )
  166.         {
  167.         if ( ferror( skelfile ) )
  168.             flexfatal(
  169.                 "error occurred when reading skeleton file" );
  170.  
  171.         else if ( fclose( skelfile ) )
  172.             flexfatal(
  173.                 "error occurred when closing skeleton file" );
  174.         }
  175.  
  176.     if ( exit_status != 0 && outfile_created )
  177.         {
  178.         if ( ferror( stdout ) )
  179.             flexfatal( "error occurred when writing output file" );
  180.  
  181.         else if ( fclose( stdout ) )
  182.             flexfatal( "error occurred when closing output file" );
  183.  
  184.         else if ( unlink( outfile_path ) )
  185.             flexfatal( "error occurred when deleting output file" );
  186.         }
  187.  
  188.     if ( backing_up_report && backing_up_file )
  189.         {
  190.         if ( num_backing_up == 0 )
  191.             fprintf( backing_up_file, "No backing up.\n" );
  192.         else if ( fullspd || fulltbl )
  193.             fprintf( backing_up_file,
  194.                 "%d backing up (non-accepting) states.\n",
  195.                 num_backing_up );
  196.         else
  197.             fprintf( backing_up_file,
  198.                 "Compressed tables always back up.\n" );
  199.  
  200.         if ( ferror( backing_up_file ) )
  201.             flexfatal( "error occurred when writing backup file" );
  202.  
  203.         else if ( fclose( backing_up_file ) )
  204.             flexfatal( "error occurred when closing backup file" );
  205.         }
  206.  
  207.     if ( printstats )
  208.         {
  209.         fprintf( stderr, "%s version %s usage statistics:\n",
  210.             program_name, flex_version );
  211.  
  212.         fprintf( stderr, "  scanner options: -" );
  213.  
  214.         if ( C_plus_plus )
  215.             putc( '+', stderr );
  216.         if ( backing_up_report )
  217.             putc( 'b', stderr );
  218.         if ( ddebug )
  219.             putc( 'd', stderr );
  220.         if ( caseins )
  221.             putc( 'i', stderr );
  222.         if ( lex_compat )
  223.             putc( 'l', stderr );
  224.         if ( performance_report > 0 )
  225.             putc( 'p', stderr );
  226.         if ( performance_report > 1 )
  227.             putc( 'p', stderr );
  228.         if ( spprdflt )
  229.             putc( 's', stderr );
  230.         if ( use_stdout )
  231.             putc( 't', stderr );
  232.         if ( printstats )
  233.             putc( 'v', stderr );    /* always true! */
  234.         if ( nowarn )
  235.             putc( 'w', stderr );
  236.         if ( ! interactive )
  237.             putc( 'B', stderr );
  238.         if ( interactive )
  239.             putc( 'I', stderr );
  240.         if ( ! gen_line_dirs )
  241.             putc( 'L', stderr );
  242.         if ( trace )
  243.             putc( 'T', stderr );
  244.         if ( csize == 128 )
  245.             putc( '7', stderr );
  246.         else
  247.             putc( '8', stderr );
  248.  
  249.         fprintf( stderr, " -C" );
  250.  
  251.         if ( long_align )
  252.             putc( 'a', stderr );
  253.         if ( fulltbl )
  254.             putc( 'f', stderr );
  255.         if ( fullspd )
  256.             putc( 'F', stderr );
  257.         if ( useecs )
  258.             putc( 'e', stderr );
  259.         if ( usemecs )
  260.             putc( 'm', stderr );
  261.         if ( use_read )
  262.             putc( 'r', stderr );
  263.  
  264.         if ( skelname )
  265.             fprintf( stderr, " -S%s", skelname );
  266.  
  267.         if ( strcmp( prefix, "yy" ) )
  268.             fprintf( stderr, " -P%s", prefix );
  269.  
  270.         putc( '\n', stderr );
  271.  
  272.         fprintf( stderr, "  %d/%d NFA states\n", lastnfa, current_mns );
  273.         fprintf( stderr, "  %d/%d DFA states (%d words)\n", lastdfa,
  274.             current_max_dfas, totnst );
  275.         fprintf( stderr, "  %d rules\n",
  276.         num_rules + num_eof_rules - 1 /* - 1 for def. rule */ );
  277.  
  278.         if ( num_backing_up == 0 )
  279.             fprintf( stderr, "  No backing up\n" );
  280.         else if ( fullspd || fulltbl )
  281.             fprintf( stderr,
  282.                 "  %d backing-up (non-accepting) states\n",
  283.                 num_backing_up );
  284.         else
  285.             fprintf( stderr,
  286.                 "  Compressed tables always back-up\n" );
  287.  
  288.         if ( bol_needed )
  289.             fprintf( stderr,
  290.                 "  Beginning-of-line patterns used\n" );
  291.  
  292.         fprintf( stderr, "  %d/%d start conditions\n", lastsc,
  293.             current_max_scs );
  294.         fprintf( stderr,
  295.             "  %d epsilon states, %d double epsilon states\n",
  296.             numeps, eps2 );
  297.  
  298.         if ( lastccl == 0 )
  299.             fprintf( stderr, "  no character classes\n" );
  300.         else
  301.             fprintf( stderr,
  302.     "  %d/%d character classes needed %d/%d words of storage, %d reused\n",
  303.                 lastccl, current_maxccls,
  304.                 cclmap[lastccl] + ccllen[lastccl],
  305.                 current_max_ccl_tbl_size, cclreuse );
  306.  
  307.         fprintf( stderr, "  %d state/nextstate pairs created\n",
  308.             numsnpairs );
  309.         fprintf( stderr, "  %d/%d unique/duplicate transitions\n",
  310.             numuniq, numdup );
  311.  
  312.         if ( fulltbl )
  313.             {
  314.             tblsiz = lastdfa * numecs;
  315.             fprintf( stderr, "  %d table entries\n", tblsiz );
  316.             }
  317.  
  318.         else
  319.             {
  320.             tblsiz = 2 * (lastdfa + numtemps) + 2 * tblend;
  321.  
  322.             fprintf( stderr, "  %d/%d base-def entries created\n",
  323.                 lastdfa + numtemps, current_max_dfas );
  324.             fprintf( stderr,
  325.                 "  %d/%d (peak %d) nxt-chk entries created\n",
  326.                 tblend, current_max_xpairs, peakpairs );
  327.             fprintf( stderr,
  328.             "  %d/%d (peak %d) template nxt-chk entries created\n",
  329.                 numtemps * nummecs, current_max_template_xpairs,
  330.                 numtemps * numecs );
  331.             fprintf( stderr, "  %d empty table entries\n", nummt );
  332.             fprintf( stderr, "  %d protos created\n", numprots );
  333.             fprintf( stderr, "  %d templates created, %d uses\n",
  334.                 numtemps, tmpuses );
  335.             }
  336.  
  337.         if ( useecs )
  338.             {
  339.             tblsiz = tblsiz + csize;
  340.             fprintf( stderr,
  341.                 "  %d/%d equivalence classes created\n",
  342.                 numecs, csize );
  343.             }
  344.  
  345.         if ( usemecs )
  346.             {
  347.             tblsiz = tblsiz + numecs;
  348.             fprintf( stderr,
  349.                 "  %d/%d meta-equivalence classes created\n",
  350.                 nummecs, csize );
  351.             }
  352.  
  353.         fprintf( stderr,
  354.             "  %d (%d saved) hash collisions, %d DFAs equal\n",
  355.             hshcol, hshsave, dfaeql );
  356.         fprintf( stderr, "  %d sets of reallocations needed\n",
  357.             num_reallocs );
  358.         fprintf( stderr, "  %d total table entries needed\n", tblsiz );
  359.         }
  360.  
  361. #ifndef VMS
  362.     exit( exit_status );
  363. #else
  364.     exit( exit_status + 1 );
  365. #endif
  366.     }
  367.  
  368.  
  369. /* flexinit - initialize flex */
  370.  
  371. void flexinit( argc, argv )
  372. int argc;
  373. char **argv;
  374.     {
  375.     int i, sawcmpflag;
  376.     int csize_given, interactive_given;
  377.     char *arg, *mktemp();
  378.  
  379.     printstats = syntaxerror = trace = spprdflt = caseins = false;
  380.     lex_compat = false;
  381.     C_plus_plus = backing_up_report = ddebug = fulltbl = fullspd = false;
  382.     long_align = nowarn = yymore_used = continued_action = reject = false;
  383.     yytext_is_array = yymore_really_used = reject_really_used = false;
  384.     gen_line_dirs = usemecs = useecs = true;
  385.     performance_report = 0;
  386.  
  387.     sawcmpflag = false;
  388.     use_read = use_stdout = false;
  389.     csize_given = false;
  390.     interactive_given = false;
  391.  
  392.     /* Initialize dynamic array for holding the rule actions. */
  393.     action_size = 2048;    /* default size of action array in bytes */
  394.     action_array = allocate_character_array( action_size );
  395.     defs1_offset = prolog_offset = action_offset = action_index = 0;
  396.     action_array[0] = '\0';
  397.  
  398.     program_name = argv[0];
  399.  
  400.     if ( program_name[0] != '\0' &&
  401.          program_name[strlen( program_name ) - 1] == '+' )
  402.         C_plus_plus = true;
  403.  
  404.     /* read flags */
  405.     for ( --argc, ++argv; argc ; --argc, ++argv )
  406.         {
  407.         if ( argv[0][0] != '-' || argv[0][1] == '\0' )
  408.             break;
  409.  
  410.         arg = argv[0];
  411.  
  412.         for ( i = 1; arg[i] != '\0'; ++i )
  413.             switch ( arg[i] )
  414.                 {
  415.                 case '+':
  416.                     C_plus_plus = true;
  417.                     break;
  418.  
  419.                 case 'B':
  420.                     interactive = false;
  421.                     interactive_given = true;
  422.                     break;
  423.  
  424.                 case 'b':
  425.                     backing_up_report = true;
  426.                     break;
  427.  
  428.                 case 'c':
  429.                     fprintf( stderr,
  430.     "%s: Assuming use of deprecated -c flag is really intended to be -C\n",
  431.                     program_name );
  432.  
  433.                     /* fall through */
  434.  
  435.                 case 'C':
  436.                     if ( i != 1 )
  437.                         flexerror(
  438.                     "-C flag must be given separately" );
  439.  
  440.                     if ( ! sawcmpflag )
  441.                         {
  442.                         useecs = false;
  443.                         usemecs = false;
  444.                         fulltbl = false;
  445.                         sawcmpflag = true;
  446.                         }
  447.  
  448.                     for ( ++i; arg[i] != '\0'; ++i )
  449.                         switch ( arg[i] )
  450.                             {
  451.                             case 'a':
  452.                                 long_align =
  453.                                     true;
  454.                                 break;
  455.  
  456.                             case 'e':
  457.                                 useecs = true;
  458.                                 break;
  459.  
  460.                             case 'F':
  461.                                 fullspd = true;
  462.                                 break;
  463.  
  464.                             case 'f':
  465.                                 fulltbl = true;
  466.                                 break;
  467.  
  468.                             case 'm':
  469.                                 usemecs = true;
  470.                                 break;
  471.  
  472.                             case 'r':
  473.                                 use_read = true;
  474.                                 break;
  475.  
  476.                             default:
  477.                                 lerrif(
  478.                         "unknown -C option '%c'",
  479.                                 (int) arg[i] );
  480.                                 break;
  481.                             }
  482.  
  483.                     goto get_next_arg;
  484.  
  485.                 case 'd':
  486.                     ddebug = true;
  487.                     break;
  488.  
  489.                 case 'f':
  490.                     useecs = usemecs = false;
  491.                     use_read = fulltbl = true;
  492.                     break;
  493.  
  494.                 case 'F':
  495.                     useecs = usemecs = false;
  496.                     use_read = fullspd = true;
  497.                     break;
  498.  
  499.                 case 'h':
  500.                     usage();
  501.                     exit( 0 );
  502.  
  503.                 case 'I':
  504.                     interactive = true;
  505.                     interactive_given = true;
  506.                     break;
  507.  
  508.                 case 'i':
  509.                     caseins = true;
  510.                     break;
  511.  
  512.                 case 'l':
  513.                     lex_compat = true;
  514.                     break;
  515.  
  516.                 case 'L':
  517.                     gen_line_dirs = false;
  518.                     break;
  519.  
  520.                 case 'n':
  521.                     /* Stupid do-nothing deprecated
  522.                      * option.
  523.                      */
  524.                     break;
  525.  
  526.                 case 'P':
  527.                     if ( i != 1 )
  528.                         flexerror(
  529.                     "-P flag must be given separately" );
  530.  
  531.                     prefix = arg + i + 1;
  532.                     goto get_next_arg;
  533.  
  534.                 case 'p':
  535.                     ++performance_report;
  536.                     break;
  537.  
  538.                 case 'S':
  539.                     if ( i != 1 )
  540.                         flexerror(
  541.                     "-S flag must be given separately" );
  542.  
  543.                     skelname = arg + i + 1;
  544.                     goto get_next_arg;
  545.  
  546.                 case 's':
  547.                     spprdflt = true;
  548.                     break;
  549.  
  550.                 case 't':
  551.                     use_stdout = true;
  552.                     break;
  553.  
  554.                 case 'T':
  555.                     trace = true;
  556.                     break;
  557.  
  558.                 case 'v':
  559.                     printstats = true;
  560.                     break;
  561.  
  562.                 case 'V':
  563.                     fprintf( stderr, "%s version %s\n",
  564.                         program_name, flex_version );
  565.                     exit( 0 );
  566.  
  567.                 case 'w':
  568.                     nowarn = true;
  569.                     break;
  570.  
  571.                 case '7':
  572.                     csize = 128;
  573.                     csize_given = true;
  574.                     break;
  575.  
  576.                 case '8':
  577.                     csize = CSIZE;
  578.                     csize_given = true;
  579.                     break;
  580.  
  581.                 default:
  582.                     fprintf( stderr,
  583.                         "%s: unknown flag '%c'\n",
  584.                         program_name, (int) arg[i] );
  585.                     usage();
  586.                     exit( 1 );
  587.                 }
  588.  
  589.         /* Used by -C, -S and -P flags in lieu of a "continue 2"
  590.          * control.
  591.          */
  592.         get_next_arg: ;
  593.         }
  594.  
  595.     if ( ! csize_given )
  596.         {
  597.         if ( (fulltbl || fullspd) && ! useecs )
  598.             csize = DEFAULT_CSIZE;
  599.         else
  600.             csize = CSIZE;
  601.         }
  602.  
  603.     if ( ! interactive_given )
  604.         {
  605.         if ( fulltbl || fullspd )
  606.             interactive = false;
  607.         else
  608.             interactive = true;
  609.         }
  610.  
  611.     if ( lex_compat )
  612.         {
  613.         if ( C_plus_plus )
  614.             flexerror( "Can't use -+ with -l option" );
  615.  
  616.         if ( fulltbl || fullspd )
  617.             flexerror( "Can't use -f or -F with -l option" );
  618.  
  619.         /* Don't rely on detecting use of yymore() and REJECT,
  620.          * just assume they'll be used.
  621.          */
  622.         yymore_really_used = reject_really_used = true;
  623.  
  624.         yytext_is_array = true;
  625.         use_read = false;
  626.         }
  627.  
  628.     if ( (fulltbl || fullspd) && usemecs )
  629.         flexerror( "-Cf/-CF and -Cm don't make sense together" );
  630.  
  631.     if ( (fulltbl || fullspd) && interactive )
  632.         flexerror( "-Cf/-CF and -I are incompatible" );
  633.  
  634.     if ( fulltbl && fullspd )
  635.         flexerror( "-Cf and -CF are mutually exclusive" );
  636.  
  637.     if ( C_plus_plus && fullspd )
  638.         flexerror( "Can't use -+ with -CF option" );
  639.  
  640.     if ( ! use_stdout )
  641.         {
  642.         FILE *prev_stdout;
  643.         char *suffix;
  644.  
  645.         if ( C_plus_plus )
  646.             suffix = "cc";
  647.         else
  648.             suffix = "c";
  649.  
  650.         sprintf( outfile_path, outfile_template, prefix, suffix );
  651.  
  652.         prev_stdout = freopen( outfile_path, "w", stdout );
  653.  
  654.         if ( prev_stdout == NULL )
  655.             lerrsf( "could not create %s", outfile_path );
  656.  
  657.         outfile_created = 1;
  658.         }
  659.  
  660.     num_input_files = argc;
  661.     input_files = argv;
  662.     set_input_file( num_input_files > 0 ? input_files[0] : NULL );
  663.  
  664.     if ( backing_up_report )
  665.         {
  666. #ifndef SHORT_FILE_NAMES
  667.         backing_up_file = fopen( "lex.backup", "w" );
  668. #else
  669.         backing_up_file = fopen( "lex.bck", "w" );
  670. #endif
  671.  
  672.         if ( backing_up_file == NULL )
  673.             flexerror( "could not create lex.backup" );
  674.         }
  675.  
  676.     else
  677.         backing_up_file = NULL;
  678.  
  679.  
  680.     lastccl = 0;
  681.     lastsc = 0;
  682.  
  683.     if ( skelname && (skelfile = fopen( skelname, "r" )) == NULL )
  684.         lerrsf( "can't open skeleton file %s", skelname );
  685.  
  686.     if ( strcmp( prefix, "yy" ) )
  687.         {
  688. #define GEN_PREFIX(name) printf( "#define yy%s %s%s\n", name, prefix, name );
  689.         GEN_PREFIX( "FlexLexer" );
  690.         GEN_PREFIX( "_create_buffer" );
  691.         GEN_PREFIX( "_delete_buffer" );
  692.         GEN_PREFIX( "_flex_debug" );
  693.         GEN_PREFIX( "_init_buffer" );
  694.         GEN_PREFIX( "_load_buffer_state" );
  695.         GEN_PREFIX( "_switch_to_buffer" );
  696.         GEN_PREFIX( "in" );
  697.         GEN_PREFIX( "leng" );
  698.         GEN_PREFIX( "lex" );
  699.         GEN_PREFIX( "out" );
  700.         GEN_PREFIX( "restart" );
  701.         GEN_PREFIX( "text" );
  702.         GEN_PREFIX( "wrap" );
  703.         printf( "\n" );
  704.         }
  705.  
  706.  
  707.     lastdfa = lastnfa = 0;
  708.     num_rules = num_eof_rules = default_rule = 0;
  709.     numas = numsnpairs = tmpuses = 0;
  710.     numecs = numeps = eps2 = num_reallocs = hshcol = dfaeql = totnst = 0;
  711.     numuniq = numdup = hshsave = eofseen = datapos = dataline = 0;
  712.     num_backing_up = onesp = numprots = 0;
  713.     variable_trailing_context_rules = bol_needed = false;
  714.  
  715.     linenum = sectnum = 1;
  716.     firstprot = NIL;
  717.  
  718.     /* Used in mkprot() so that the first proto goes in slot 1
  719.      * of the proto queue.
  720.      */
  721.     lastprot = 1;
  722.  
  723.     if ( useecs )
  724.         {
  725.         /* Set up doubly-linked equivalence classes. */
  726.  
  727.         /* We loop all the way up to csize, since ecgroup[csize] is
  728.          * the position used for NUL characters.
  729.          */
  730.         ecgroup[1] = NIL;
  731.  
  732.         for ( i = 2; i <= csize; ++i )
  733.             {
  734.             ecgroup[i] = i - 1;
  735.             nextecm[i - 1] = i;
  736.             }
  737.  
  738.         nextecm[csize] = NIL;
  739.         }
  740.  
  741.     else
  742.         {
  743.         /* Put everything in its own equivalence class. */
  744.         for ( i = 1; i <= csize; ++i )
  745.             {
  746.             ecgroup[i] = i;
  747.             nextecm[i] = BAD_SUBSCRIPT;    /* to catch errors */
  748.             }
  749.         }
  750.  
  751.     set_up_initial_allocations();
  752.     }
  753.  
  754.  
  755. /* readin - read in the rules section of the input file(s) */
  756.  
  757. void readin()
  758.     {
  759.     skelout();
  760.  
  761.     line_directive_out( (FILE *) 0 );
  762.  
  763.     if ( yyparse() )
  764.         {
  765.         pinpoint_message( "fatal parse error" );
  766.         flexend( 1 );
  767.         }
  768.  
  769.     if ( syntaxerror )
  770.         flexend( 1 );
  771.  
  772.     if ( yymore_really_used == REALLY_USED )
  773.         yymore_used = true;
  774.     else if ( yymore_really_used == REALLY_NOT_USED )
  775.         yymore_used = false;
  776.  
  777.     if ( reject_really_used == REALLY_USED )
  778.         reject = true;
  779.     else if ( reject_really_used == REALLY_NOT_USED )
  780.         reject = false;
  781.  
  782.     if ( performance_report > 0 )
  783.         {
  784.         if ( lex_compat )
  785.             {
  786.             fprintf( stderr,
  787. "-l AT&T lex compatibility option entails a large performance penalty\n" );
  788.             fprintf( stderr,
  789. " and may be the actual source of other reported performance penalties\n" );
  790.             }
  791.  
  792.         if ( performance_report > 1 )
  793.             {
  794.             if ( interactive )
  795.                 fprintf( stderr,
  796.         "-I (interactive) entails a minor performance penalty\n" );
  797.  
  798.             if ( yymore_used )
  799.                 fprintf( stderr,
  800.             "yymore() entails a minor performance penalty\n" );
  801.             }
  802.  
  803.         if ( reject )
  804.             fprintf( stderr,
  805.             "REJECT entails a large performance penalty\n" );
  806.  
  807.         if ( variable_trailing_context_rules )
  808.             fprintf( stderr,
  809. "Variable trailing context rules entail a large performance penalty\n" );
  810.         }
  811.  
  812.     if ( reject )
  813.         real_reject = true;
  814.  
  815.     if ( variable_trailing_context_rules )
  816.         reject = true;
  817.  
  818.     if ( (fulltbl || fullspd) && reject )
  819.         {
  820.         if ( real_reject )
  821.             flexerror( "REJECT cannot be used with -f or -F" );
  822.         else
  823.             flexerror(
  824.     "variable trailing context rules cannot be used with -f or -F" );
  825.         }
  826.  
  827.     if ( csize == 256 )
  828.         puts( "typedef unsigned char YY_CHAR;" );
  829.     else
  830.         puts( "typedef char YY_CHAR;" );
  831.  
  832.     if ( C_plus_plus )
  833.         {
  834.         puts( "#define yytext_ptr yytext" );
  835.  
  836.         if ( interactive )
  837.             puts( "#define YY_INTERACTIVE" );
  838.         }
  839.  
  840.     if ( fullspd )
  841.         printf(
  842.         "typedef const struct yy_trans_info *yy_state_type;\n" );
  843.     else if ( ! C_plus_plus )
  844.         printf( "typedef int yy_state_type;\n" );
  845.  
  846.     if ( reject )
  847.         printf( "\n#define YY_USES_REJECT\n" );
  848.  
  849.     if ( ddebug )
  850.         puts( "\n#define FLEX_DEBUG" );
  851.  
  852.     if ( lex_compat )
  853.         {
  854.         printf( "FILE *yyin = stdin, *yyout = stdout;\n" );
  855.         printf( "extern int yylineno;\n" );
  856.         printf( "int yylineno = 1;\n" );
  857.         }
  858.     else if ( ! C_plus_plus )
  859.         printf( "FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;\n" );
  860.  
  861.     if ( C_plus_plus )
  862.         printf( "\n#include <FlexLexer.h>\n" );
  863.  
  864.     else
  865.         {
  866.         if ( yytext_is_array )
  867.             puts( "extern char yytext[];\n" );
  868.  
  869.         else
  870.             {
  871.             puts( "extern char *yytext;" );
  872.             puts( "#define yytext_ptr yytext" );
  873.             }
  874.         }
  875.  
  876.     if ( useecs )
  877.         numecs = cre8ecs( nextecm, ecgroup, csize );
  878.     else
  879.         numecs = csize;
  880.  
  881.     /* Now map the equivalence class for NUL to its expected place. */
  882.     ecgroup[0] = ecgroup[csize];
  883.     NUL_ec = ABS( ecgroup[0] );
  884.  
  885.     if ( useecs )
  886.         ccl2ecl();
  887.     }
  888.  
  889.  
  890. /* set_up_initial_allocations - allocate memory for internal tables */
  891.  
  892. void set_up_initial_allocations()
  893.     {
  894.     current_mns = INITIAL_MNS;
  895.     firstst = allocate_integer_array( current_mns );
  896.     lastst = allocate_integer_array( current_mns );
  897.     finalst = allocate_integer_array( current_mns );
  898.     transchar = allocate_integer_array( current_mns );
  899.     trans1 = allocate_integer_array( current_mns );
  900.     trans2 = allocate_integer_array( current_mns );
  901.     accptnum = allocate_integer_array( current_mns );
  902.     assoc_rule = allocate_integer_array( current_mns );
  903.     state_type = allocate_integer_array( current_mns );
  904.  
  905.     current_max_rules = INITIAL_MAX_RULES;
  906.     rule_type = allocate_integer_array( current_max_rules );
  907.     rule_linenum = allocate_integer_array( current_max_rules );
  908.     rule_useful = allocate_integer_array( current_max_rules );
  909.  
  910.     current_max_scs = INITIAL_MAX_SCS;
  911.     scset = allocate_integer_array( current_max_scs );
  912.     scbol = allocate_integer_array( current_max_scs );
  913.     scxclu = allocate_integer_array( current_max_scs );
  914.     sceof = allocate_integer_array( current_max_scs );
  915.     scname = allocate_char_ptr_array( current_max_scs );
  916.     actvsc = allocate_integer_array( current_max_scs );
  917.  
  918.     current_maxccls = INITIAL_MAX_CCLS;
  919.     cclmap = allocate_integer_array( current_maxccls );
  920.     ccllen = allocate_integer_array( current_maxccls );
  921.     cclng = allocate_integer_array( current_maxccls );
  922.  
  923.     current_max_ccl_tbl_size = INITIAL_MAX_CCL_TBL_SIZE;
  924.     ccltbl = allocate_Character_array( current_max_ccl_tbl_size );
  925.  
  926.     current_max_dfa_size = INITIAL_MAX_DFA_SIZE;
  927.  
  928.     current_max_xpairs = INITIAL_MAX_XPAIRS;
  929.     nxt = allocate_integer_array( current_max_xpairs );
  930.     chk = allocate_integer_array( current_max_xpairs );
  931.  
  932.     current_max_template_xpairs = INITIAL_MAX_TEMPLATE_XPAIRS;
  933.     tnxt = allocate_integer_array( current_max_template_xpairs );
  934.  
  935.     current_max_dfas = INITIAL_MAX_DFAS;
  936.     base = allocate_integer_array( current_max_dfas );
  937.     def = allocate_integer_array( current_max_dfas );
  938.     dfasiz = allocate_integer_array( current_max_dfas );
  939.     accsiz = allocate_integer_array( current_max_dfas );
  940.     dhash = allocate_integer_array( current_max_dfas );
  941.     dss = allocate_int_ptr_array( current_max_dfas );
  942.     dfaacc = allocate_dfaacc_union( current_max_dfas );
  943.  
  944.     nultrans = (int *) 0;
  945.     }
  946.  
  947.  
  948. void usage()
  949.     {
  950.     fprintf( stderr,
  951. "%s [-bcdfhilnpstvwBFILTV78+ -C[aefFmr] -Pprefix -Sskeleton] [file ...]\n",
  952.         program_name );
  953.  
  954.     fprintf( stderr,
  955.         "\t-b  generate backing-up information to lex.backup\n" );
  956.     fprintf( stderr, "\t-c  do-nothing POSIX option\n" );
  957.     fprintf( stderr, "\t-d  turn on debug mode in generated scanner\n" );
  958.     fprintf( stderr, "\t-f  generate fast, large scanner\n" );
  959.     fprintf( stderr, "\t-h  produce this help message\n" );
  960.     fprintf( stderr, "\t-i  generate case-insensitive scanner\n" );
  961.     fprintf( stderr, "\t-l  maximal compatibility with original lex\n" );
  962.     fprintf( stderr, "\t-n  do-nothing POSIX option\n" );
  963.     fprintf( stderr, "\t-p  generate performance report to stderr\n" );
  964.     fprintf( stderr,
  965.         "\t-s  suppress default rule to ECHO unmatched text\n" );
  966.     fprintf( stderr,
  967.     "\t-t  write generated scanner on stdout instead of lex.yy.c\n" );
  968.     fprintf( stderr,
  969.         "\t-v  write summary of scanner statistics to stderr\n" );
  970.     fprintf( stderr, "\t-w  do not generate warnings\n" );
  971.     fprintf( stderr, "\t-B  generate batch scanner (opposite of -I)\n" );
  972.     fprintf( stderr,
  973.         "\t-F  use alternative fast scanner representation\n" );
  974.     fprintf( stderr,
  975.         "\t-I  generate interactive scanner (opposite of -B)\n" );
  976.     fprintf( stderr, "\t-L  suppress #line directives in scanner\n" );
  977.     fprintf( stderr, "\t-T  %s should run in trace mode\n", program_name );
  978.     fprintf( stderr, "\t-V  report %s version\n", program_name );
  979.     fprintf( stderr, "\t-7  generate 7-bit scanner\n" );
  980.     fprintf( stderr, "\t-8  generate 8-bit scanner\n" );
  981.     fprintf( stderr, "\t-+  generate C++ scanner class\n" );
  982.     fprintf( stderr,
  983.     "\t-C  specify degree of table compression (default is -Cem):\n" );
  984.     fprintf( stderr,
  985.     "\t\t-Ca  trade off larger tables for better memory alignment\n" );
  986.     fprintf( stderr, "\t\t-Ce  construct equivalence classes\n" );
  987.     fprintf( stderr,
  988.     "\t\t-Cf  do not compress scanner tables; use -f representation\n" );
  989.     fprintf( stderr,
  990.     "\t\t-CF  do not compress scanner tables; use -F representation\n" );
  991.     fprintf( stderr, "\t\t-Cm  construct meta-equivalence classes\n" );
  992.     fprintf( stderr,
  993.         "\t\t-Cr  use read() instead of stdio for scanner input\n" );
  994.     fprintf( stderr, "\t-P  specify scanner prefix other than \"yy\"\n" );
  995.     fprintf( stderr, "\t-S  specify skeleton file\n" );
  996.     }
  997.